package com.ruoyi.web.controller.food;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.food.domain.CornTakeOff;
import com.ruoyi.food.service.ICornTakeOffService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 玉米脱粒记录Controller
 * 
 * @author ruoyi
 * @date 2025-04-13
 */
@RestController
@RequestMapping("/food/corn")
public class CornTakeOffController extends BaseController
{
    @Autowired
    private ICornTakeOffService cornTakeOffService;

    /**
     * 查询玉米脱粒记录列表
     */
    @ApiOperation("玉米脱粒记录")
    @PreAuthorize("@ss.hasPermi('food:corn:list')")
    @GetMapping("/list")
    public TableDataInfo list(CornTakeOff cornTakeOff)
    {
        startPage();
        List<CornTakeOff> list = cornTakeOffService.selectCornTakeOffList(cornTakeOff);
        return getDataTable(list);
    }

    /**
     * 导出玉米脱粒记录列表
     */
    @PreAuthorize("@ss.hasPermi('food:corn:export')")
    @Log(title = "玉米脱粒记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CornTakeOff cornTakeOff)
    {
        List<CornTakeOff> list = cornTakeOffService.selectCornTakeOffList(cornTakeOff);
        ExcelUtil<CornTakeOff> util = new ExcelUtil<CornTakeOff>(CornTakeOff.class);
        util.exportExcel(response, list, "玉米脱粒记录数据");
    }

    /**
     * 获取玉米脱粒记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('food:corn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cornTakeOffService.selectCornTakeOffById(id));
    }

    /**
     * 新增玉米脱粒记录
     */
    @PreAuthorize("@ss.hasPermi('food:corn:add')")
    @Log(title = "玉米脱粒记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CornTakeOff cornTakeOff)
    {
        return toAjax(cornTakeOffService.insertCornTakeOff(cornTakeOff));
    }

    /**
     * 修改玉米脱粒记录
     */
    @PreAuthorize("@ss.hasPermi('food:corn:edit')")
    @Log(title = "玉米脱粒记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CornTakeOff cornTakeOff)
    {
        return toAjax(cornTakeOffService.updateCornTakeOff(cornTakeOff));
    }

    /**
     * 删除玉米脱粒记录
     */
    @PreAuthorize("@ss.hasPermi('food:corn:remove')")
    @Log(title = "玉米脱粒记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cornTakeOffService.deleteCornTakeOffByIds(ids));
    }
}
